package com.jiangjun.fetch.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class PicShowAction extends DispatchAction{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String type = request.getParameter("type");
		String cpage = request.getParameter("cpage");
		String url = "http://192.168.10.54:8092/netfetchInterFace/getInfoListService?type=" +type+ "&cpage=" + cpage;			
		HttpGet httpGet = new HttpGet(url);
		DefaultHttpClient httpClient = new DefaultHttpClient();
		HttpResponse res = httpClient.execute(httpGet);
		String result = EntityUtils.toString(res.getEntity(), "utf-8");
		System.out.println(result);
		response.setCharacterEncoding("utf-8");
		PrintWriter pw = response.getWriter();
		response.setContentType("application/json");
		pw.print(result);
		pw.flush();
		pw.close();
		return null;
	}
}
